// app/controller/home.js
const jwt = require('jsonwebtoken');
const Controller = require('../core/base_controller');

class UserController extends Controller {
  async login() {
    const {username,password} = this.ctx.request.body;
    let result = await this.service.user.login({username,password});
    if(typeof result ==='string'){
      this.ctx.body = {
        meta:{
          status:203,
          mag:"登录失败",
        }
      }
    } else {
      console.log(result);
      const {avatar,nickname,sales_volume} = result;
      this.ctx.body = {
        meta:{
          status:200,
          msg:"登录成功"
        },
        data:{
          token:jwt.sign({...result},this.app.config.keys),
          nickname,
          avatar,
          sales_volume,
        }
      }
    }
  
  }
  async register() {
    this.ctx.body = '注册';
  }
}

module.exports = UserController;